public class Solution809 {
    public int expressiveWords(String s, String[] words) {
        int ans=0;
        for (String word : words) {
            int c1=0,c2=0,flag=1;
            while (c1<s.length() && c2<word.length()){
                if (s.charAt(c1)!=word.charAt(c2)){
                    flag=-1;
                    break;
                }
                int last1=c1;
                while (c1+1<s.length() && s.charAt(c1)==s.charAt(c1+1)){
                    c1++;
                }
                int last2=c2;
                while (c2+1<word.length() && word.charAt(c2)==word.charAt(c2+1)){
                    c2++;
                }
                if (c1-last1<=1 && c2-last2!=c1-last1 || c2-last2>c1-last1){
                    flag=-1;
                    break;
                }
                c1++;
                c2++;
            }
            if (flag==1 && c1==s.length() && c2==word.length()){
                ans++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution809().expressiveWords("heeellooo",new String[]{"hello", "hi", "helo"}));
    }
}
